#include <stdio.h>

#define BIT_SET(x,n)		((x) |= (n)) 
#define BIT_GET(x,n)		((x) & (n))
#define BIT_CLR(x,n) 		((x) &= ~((n)))

/**	错误思路：
 *	0001		1110       -> 1111  			  0000
 *  val       val ~= val -> val |= (1 << n)       val ~= val
 * 
 * mistake : 按位取反 语法错误 2025.5.7
 * 			#define BIT_CLR(x,n)		do{x ~= x;  x |= n;	\
 * 											x ~= x; 			\
 * 										}while(0)
 * 正确： 
 * 0010       0010 & ~(1 << 1)  ->  0010 & 1101	   0000
 */

#define  DO_SOMETHING   (1 << 0)
#define  LEAN_MUSIC		(1 << 1)



char byte = 0;

void printBin(char byte)
{
	for(int i = 0; i < 8; i++){
		printf("%d",(byte >> (7 - i)&0x01));
		if(i == 3) printf(" ");
	}
	printf("\n");
}
void printBinArry(char *buf, int len)
{
	for(int i=0;i<len;i++){
		printBin(buf[i]);
	}
	
}


int main()
{
	printBin(byte);
	BIT_SET(byte,DO_SOMETHING);
	printBin(byte);
	BIT_SET(byte,LEAN_MUSIC);
	printBin(byte);
	if(BIT_GET(byte,DO_SOMETHING))		
		printf("I'm Done!\n");

	if(BIT_GET(byte,LEAN_MUSIC))		
		printf("I'm Learning!!\n");

	BIT_CLR(byte,LEAN_MUSIC);
	printBin(byte);
	if(!BIT_GET(byte,LEAN_MUSIC))		
		printf("I'm quit...\n");
	
	

	return 0;
}
